package com.sanpu.kxe.business.repay.view;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.member.provider.IMemberProvider;
import com.sanpu.kxe.business.repay.bean.RateDetailsOutput;
import com.sanpu.kxe.business.repay.contract.RateDetailsContract;
import com.sanpu.kxe.business.repay.presenter.RateDetailsPresenter;
import com.sanpu.kxe.utils.PublicProviderUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Description：费率表
 * Created by 薛勇军 on 2019/4/10.
 */

public class RateDetailsActivity extends BaseTitleActivity implements RateDetailsContract.View {

    @Bind(R.id.expenseLvl1)
    TextView expenseLvl1;
    @Bind(R.id.expenseLvl2)
    TextView expenseLvl2;
    @Bind(R.id.expenseLvl3)
    TextView expenseLvl3;
    @Bind(R.id.expenseLvl4)
    TextView expenseLvl4;

    @Bind(R.id.repayLvl1)
    TextView repayLvl1;
    @Bind(R.id.repayLvl2)
    TextView repayLvl2;
    @Bind(R.id.repayLvl3)
    TextView repayLvl3;
    @Bind(R.id.repayLvl4)
    TextView repayLvl4;

    @Bind(R.id.levelNameTv1)
    TextView levelNameTv1;
    @Bind(R.id.levelNameTv2)
    TextView levelNameTv2;
    @Bind(R.id.levelNameTv3)
    TextView levelNameTv3;
    @Bind(R.id.levelNameTv4)
    TextView levelNameTv4;

    private RateDetailsContract.Presenter mPresenter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_rate_details;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("代还");
        mPresenter = new RateDetailsPresenter(this);
        mPresenter.repayFeeList();
    }

    @OnClick({R.id.next})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.next:
                IMemberProvider provider = PublicProviderUtil.getProvider(IMemberProvider.class);
                if (provider != null) {
                    provider.openMemberLevelsListActivity(mContext);
                }
                break;
        }
    }

    @Override
    public void showDataView(List<RateDetailsOutput> rateDetailsOutputs) {
        try {
            if (rateDetailsOutputs != null && rateDetailsOutputs.size() > 0) {
                for (int index = 0; index < rateDetailsOutputs.size(); index++) {
                    RateDetailsOutput detailsOutput = rateDetailsOutputs.get(index);
                    if (detailsOutput != null) {
                        switch (index) {
                            case 0:
                                levelNameTv1.setText(detailsOutput.getLevelName());
                                expenseLvl1.setText(detailsOutput.getTradeRate());
                                repayLvl1.setText(detailsOutput.getExtraCharge());
                                break;
                            case 1:
                                levelNameTv2.setText(detailsOutput.getLevelName());
                                expenseLvl2.setText(detailsOutput.getTradeRate());
                                repayLvl2.setText(detailsOutput.getExtraCharge());
                                break;
                            case 2:
                                levelNameTv3.setText(detailsOutput.getLevelName());
                                expenseLvl3.setText(detailsOutput.getTradeRate());
                                repayLvl3.setText(detailsOutput.getExtraCharge());
                                break;
                            case 3:
                                levelNameTv4.setText(detailsOutput.getLevelName());
                                expenseLvl4.setText(detailsOutput.getTradeRate());
                                repayLvl4.setText(detailsOutput.getExtraCharge());
                                break;
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(RateDetailsContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
